package com.foxit.adapp;
import java.util.Random;
public class GenAD {   
     private String[] glist;
     public GenAD() {
        this.glist = null;
     }
     public GenAD(String msglist) {
        if(msglist!=null && msglist.length()!=0) {
           this.glist = msglist.split(",");
        } else
           this.glist = null;
     }
     public String getAD() { 
        if(glist == null) {
           return "";
        }
        if(glist.length==1) return glist[0];
        Random rand = new Random();
        int v = rand.nextInt(glist.length);
        return glist[v]; 
     }
     public String[] getADS(int maxno) {
        if(glist == null) return null;
        if(glist.length <= maxno) {
           return glist;
        }
        Random rand = new Random();
        int v = rand.nextInt(glist.length);
        int n=0,i=0;
        String[] a= new String[maxno];
        for (i=v;i < glist.length;i++) {
           a[n++] = glist[i];
           if( n == maxno ) break;
        }
        if(n == maxno) return a;
        for (i=0;i < glist.length;i++) {
           a[n++] = glist[i];
           if( n == maxno ) break;
        }
        return a;
     }

}
